
import unittest

global_value = 1

class TestNameSpace(unittest.TestCase):
    
    def _func_shadow_global(self,newvalue):
        """
        by creating a local identifier with same name as global one
        glboal identifier is shadow in the function's scope
        """
        global_value = newvalue
        return global_value 
    
    def _func_using_global_keyword(self,newvalue):
        """
        by using "global" keyword, same-name identifier will not shadow global ones
        """
        global global_value
        global_value = newvalue
    
    def test_global_keyword(self):
        # ------------- shadow
        value_inside_func = self._func_shadow_global("cheka")
        self.assertEqual("cheka",value_inside_func)
        self.assertEqual(1,global_value)
        
        # ------------- global keyword
        self._func_using_global_keyword("stasi")
        self.assertEqual("stasi",global_value)
    
if __name__ == "__main__":
    unittest.main()